package com.example.iotest.bio;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

@Slf4j
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress(8081));
        log.info("服务器启动成功");
        while (true) {
            Socket accept = serverSocket.accept();
            InetAddress inetAddress = accept.getInetAddress();
            System.out.println(inetAddress+"连接");
            OutputStream outputStream = accept.getOutputStream();
            FileInputStream fileInputStream = new FileInputStream("K:\\电影\\未麻的部屋BD日语中字[电影天堂www.dy2018.com].mp4");
            byte[] buffer = new byte[1024];
            int length;
            while ((length = fileInputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, length);
            }
            fileInputStream.close();
            outputStream.close();
        }
    }
}
